package com.petshop.productcategories.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.petshop.common.annotation.Log;
import com.petshop.common.core.controller.BaseController;
import com.petshop.common.core.domain.AjaxResult;
import com.petshop.common.enums.BusinessType;
import com.petshop.productcategories.domain.PetProductcategories;
import com.petshop.productcategories.service.IPetProductcategoriesService;
import com.petshop.common.utils.poi.ExcelUtil;
import com.petshop.common.core.page.TableDataInfo;

/**
 * 商品类别Controller
 * 
 * @author ruoyi
 * @date 2024-09-11
 */
@RestController
@RequestMapping("/productcategories/productcategories")
public class PetProductcategoriesController extends BaseController
{
    @Autowired
    private IPetProductcategoriesService petProductcategoriesService;

    /**
     * 查询商品类别列表
     */
    @PreAuthorize("@ss.hasPermi('productcategories:productcategories:list')")
    @GetMapping("/list")
    public TableDataInfo list(PetProductcategories petProductcategories)
    {
        startPage();
        List<PetProductcategories> list = petProductcategoriesService.selectPetProductcategoriesList(petProductcategories);
        return getDataTable(list);
    }

    /**
     * 导出商品类别列表
     */
    @PreAuthorize("@ss.hasPermi('productcategories:productcategories:export')")
    @Log(title = "商品类别", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PetProductcategories petProductcategories)
    {
        List<PetProductcategories> list = petProductcategoriesService.selectPetProductcategoriesList(petProductcategories);
        ExcelUtil<PetProductcategories> util = new ExcelUtil<PetProductcategories>(PetProductcategories.class);
        util.exportExcel(response, list, "商品类别数据");
    }

    /**
     * 获取商品类别详细信息
     */
    @PreAuthorize("@ss.hasPermi('productcategories:productcategories:query')")
    @GetMapping(value = "/{categoryID}")
    public AjaxResult getInfo(@PathVariable("categoryID") Long categoryID)
    {
        return success(petProductcategoriesService.selectPetProductcategoriesByCategoryID(categoryID));
    }

    /**
     * 新增商品类别
     */
    @PreAuthorize("@ss.hasPermi('productcategories:productcategories:add')")
    @Log(title = "商品类别", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PetProductcategories petProductcategories)
    {
        return toAjax(petProductcategoriesService.insertPetProductcategories(petProductcategories));
    }

    /**
     * 修改商品类别
     */
    @PreAuthorize("@ss.hasPermi('productcategories:productcategories:edit')")
    @Log(title = "商品类别", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PetProductcategories petProductcategories)
    {
        return toAjax(petProductcategoriesService.updatePetProductcategories(petProductcategories));
    }

    /**
     * 删除商品类别
     */
    @PreAuthorize("@ss.hasPermi('productcategories:productcategories:remove')")
    @Log(title = "商品类别", businessType = BusinessType.DELETE)
	@DeleteMapping("/{categoryIDs}")
    public AjaxResult remove(@PathVariable Long[] categoryIDs)
    {
        return toAjax(petProductcategoriesService.deletePetProductcategoriesByCategoryIDs(categoryIDs));
    }
}
